﻿using M_ApiResult;
using M_Quality.API.Application.Command.QualitygroupCommand;
using M_Quality.API.Application.Command.QualityPlanCommand;
using M_Quality.API.Application.Command.QualityProgromCommand;
using M_Quality.API.Application.Command.ReinspectionCommand;
using M_Quality.Domain;
using M_Quality.Domain.Dto;
using MediatR;
using Microsoft.AspNetCore.Components.Forms;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace M_Quality.API.Controllers
{
    /// <summary>
    /// 复检
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ReInspectionController : ControllerBase
    {
        /// <summary>
        /// 中介者
        /// </summary>
        protected readonly IMediator _mediator;

        public ReInspectionController(IMediator mediator)
        {
            _mediator = mediator;
        }
        /// <summary>
        /// 添加复检信息
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> AddReInspection(CreateReinspectionCommand command)
        {
            ApiResult<int> result = new ApiResult<int>();
            try
            {

                result.Code = await _mediator.Send(command);
            }
            catch (Exception)
            {
                result.Code = -1;
                result.Message = "添加复检信息失败";
                throw;
            }
            return result;

        }
        /// <summary>
        /// 显示复检信息
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult<PageDto<Reinspection>>> GetQualityPlanList([FromQuery] ShowReinspectionCommand command)
        {
            ApiResult<PageDto<Reinspection>> result = new ApiResult<PageDto<Reinspection>>();
            try
            {
                result.Data = await _mediator.Send(command);
            }
            catch (Exception)
            {
                result.Code = -1;
                result.Message = "显示复检信息失败";
                throw;
            }
            return result;
        }
        /// <summary>
        /// 删除复检信息
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> DelReInforce([FromQuery]DeleteReinspectionCommand command)
        {
            ApiResult<int> result = new ApiResult<int>();

            try
            {
                result.Code = await _mediator.Send(command);
            }
            catch (Exception)
            {
                result.Code = -1;
                result.Message = "删除复检信息失败";
                throw;
            }
            return result;
        }
        /// <summary>
        /// 反填查看复检信息
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult<List<ReDto>>> GetByidReInsp([FromQuery] GetByidReinspectionCommand command)
        {
            ApiResult<List<ReDto>> result = new ApiResult<List<ReDto>>();
            try
            {
                result.Data = await _mediator.Send(command);
            }
            catch (Exception ex)
            {
                result.Code = -1;
                result.Message = ex.Message;
                throw;
            }
            return result;

        }
        /// <summary>
        /// 销毁
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> XiaohuiReIns([FromQuery] XiaohuiReinspectionCommand command)
        {
            ApiResult<int> result = new ApiResult<int>();
            try
            {
                result.Code = await _mediator.Send(command);
            }
            catch (Exception)
            {
                result.Code = -1;
                result.Message = "销毁失败";
                throw;
            }
            return result;
        }
        /// <summary>
        /// 待复检去复检
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> UpdateReInspection(UpdateReinspectionCommand command)
        {
            ApiResult<int> result = new ApiResult<int>();
            try
            {

                result.Code = await _mediator.Send(command);
            }
            catch (Exception)
            {
                result.Code = -1;
                result.Message = "修改复检信息失败";
                throw;
            }
            return result;

        }

    }
}
